﻿package plugin.gameHall.game
{
    import com.core.*;
    import flash.events.*;
    import flash.external.*;
    import flash.utils.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.gameHall.*;
    import plugin.platform.*;
    import uiresource.gameHall.*;
    import view.mornExtends.*;
    import vo.*;

    public class ThreeHallCon extends ThreeUI
    {
        private var _instance:ThreeHall;
        private var wslv:Array;
        private var timeindex:int = -1;
        private var _timeID:uint = 0;

        public function ThreeHallCon(param1:ThreeHall)
        {
            this._instance = param1;
            return;
        }// end function

        override protected function initializeView() : void
        {
            var _loc_1:* = Control.create(ThreeHallControl, this);
            ModelProxy.addObserver("threehall", _loc_1);
            btn_colse.clickHandler = new Handler(this.close);
            libaoLink.clickHandler = new Handler(this.libaoLinkclick);
            return;
        }// end function

        private function libaoLinkclick() : void
        {
            ExternalInterface.call("privilege");
            return;
        }// end function

        private function close() : void
        {
            this._instance.close();
            return;
        }// end function

        public function openRefresh() : void
        {
            this.showList();
            return;
        }// end function

        public function showList() : void
        {
            var _loc_2:String = null;
            if (this.wslv == null)
            {
                this.wslv = ModelProxy.getValue("data", "configs.wslv");
            }
            var _loc_1:Array = [];
            for (_loc_2 in this.wslv)
            {
                
                _loc_1.push(this.wslv[_loc_2]);
            }
            list.renderHandler = new Handler(this.itemHandler);
            list.array = _loc_1;
            return;
        }// end function

        private function itemHandler(param1:Component, param2:int) : void
        {
            (param1.getChildByName("lvLabel") as Label).text = "LV:" + param1.dataSource.lv.toString();
            var _loc_3:* = ModelProxy.getValue("data", "wslvgifti");
            if (_loc_3 && _loc_3.indexOf(int(param1.dataSource.lv)) >= 0)
            {
                (param1.getChildByName("btn_lingqu") as Button).label = "已领取";
                (param1.getChildByName("btn_lingqu") as Button).disabled = true;
            }
            else
            {
                (param1.getChildByName("btn_lingqu") as Button).label = "领取";
                (param1.getChildByName("btn_lingqu") as Button).disabled = false;
            }
            (param1.getChildByName("btn_lingqu") as Button).removeEventListener(MouseEvent.CLICK, this.btn_lingquClickHandler);
            (param1.getChildByName("btn_lingqu") as Button).addEventListener(MouseEvent.CLICK, this.btn_lingquClickHandler);
            var _loc_4:* = int(param1.dataSource.boxid);
            this.showItem(param1.getChildByName("itemlist") as List, _loc_4);
            return;
        }// end function

        private function btn_lingquClickHandler(event:Event) : void
        {
            var _loc_2:* = ((event.currentTarget as Button).parent as Component).dataSource.lv;
            if (this.timeindex == _loc_2)
            {
                return;
            }
            PlatformSender._3360Antivirus(_loc_2);
            if (this._timeID > 0)
            {
                clearTimeout(this._timeID);
                this._timeID = 0;
            }
            this.timeindex = _loc_2;
            this._timeID = setTimeout(this.timeFun, 2000);
            return;
        }// end function

        private function timeFun() : void
        {
            this.timeindex = -1;
            return;
        }// end function

        private function showItem(param1:List, param2:int) : void
        {
            var _loc_8:String = null;
            var _loc_9:Array = null;
            var _loc_10:Object = null;
            var _loc_3:* = ConfigDictionary.data.box;
            var _loc_4:* = ConfigDictionary.data.item;
            var _loc_5:Array = [];
            var _loc_6:* = (_loc_3[param2].items as String).split(";");
            var _loc_7:int = 0;
            while (_loc_7 < _loc_6.length)
            {
                
                _loc_8 = _loc_6[_loc_7];
                _loc_9 = _loc_8.split("-");
                if (_loc_9.length >= 4)
                {
                    if (_loc_9[3] != 2 && _loc_9[3] != ModelProxy.getValue("data", "user.sex"))
                    {
                        ;
                    }
                }
                if (_loc_9.length >= 5)
                {
                    if (_loc_9[4] != 0 && _loc_9[4] != ModelProxy.getValue("data", "user.career"))
                    {
                        ;
                    }
                }
                _loc_10 = ItemObject.create(_loc_4[_loc_9[0]]);
                _loc_10.count = _loc_9[1];
                _loc_5.push(_loc_10);
                _loc_7++;
            }
            param1.array = _loc_5;
            param1.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param1 && param1.dataSource)
            {
                (param1.getChildByName("item") as FlashItem).data = param1.dataSource;
            }
            return;
        }// end function

    }
}
